<?php

namespace App\Http\Middleware;

use App\Setting;
use Closure;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;

class WebConfig
{
    protected $site_config;
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //得到网站配置
        $this->get_siteConfig();
        //设置语言
        $lang=session('lang') ? session('lang') : 'zh-CN';

        App::setLocale($lang);
        return $next($request);
    }
    /*
      * 得到网站配置
      */
    public function get_siteConfig(){
        $this->site_config= Cache::remember('site_config',10,function(){
            return Setting::all()->pluck('value', 'name');
        });
    }

}
